#!/bin/bash

if [ $# -lt 1 ]; then
    echo "usage: $0 <compile dir>"
    exit 1
fi

if [ ! -d $1 ]; then
    echo "error: directory [$1] not exist!"
    exit 1
fi

TARGET=
if [ $# -eq 2 ]; then
    TARGET=$2
fi

cp -f Makefile $1

WORD_DIR=`pwd`
cd $1
make $TARGET
cd $WORD_DIR
echo "build successfully!"
